package com.ds.api.job;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import com.ds.api.dao.TypeMachineMapper;
import com.ds.api.utils.Utils;

@Service
public class TypeMachineTask {
    
    @Autowired
    private TypeMachineMapper mapper;
    
    /**
     * 器械类缓存
     * 、*
     */
//    @Scheduled(cron="0/20 * * * * ?")
    @Scheduled(cron=" 0 0 2 * * ?")
    public void machineTask(){
        Map<String, Object> childrenMap = null;
        
        List<Map<String,Object>> add=new ArrayList<Map<String,Object>>();
        
        Map<String,Object> param=new HashMap<String,Object>();
        Map<String,Object> param2=new HashMap<String,Object>();

        param.put("fkParentId", 39);
        List<Map<String,Object>> lists=mapper.queryTree(param);
        for (Map<String,Object> model : lists) {

            childrenMap = new  LinkedHashMap<String, Object>();

            param2.put("fkParentId", model.get("value"));
            List<Map<String,Object>> list1=mapper.queryTree(param2);
            if(list1.size()>0){
                model.put("children", list1);
                for (Map<String, Object> map : list1) {
                    param2.clear();
                    param2.put("fkParentId", map.get("value"));
                    List<Map<String,Object>>  list3=mapper.queryTree(param2);
                    map.put("children", list3);
                }
            }
            add.add(model);
        }
        Utils.childlist=add;
    }
}
